home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT03.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  2.8 KB  |  76 lines

  1. /*
  2. ==============================================================================
  3.                       WordUp Graphics Toolkit Version 5.0                     
  4.                              Demonstration Program 3                          
  5.                                                                               
  6.  Clears the screen with random colours until you hit a key, and times how
  7.  fast the system is at writing to video memory.  It will report the highest
  8.  frame rate possible for copying 64k to the video card.
  9.                                                                               
  10.  *** PROJECT ***                                                             
  11.  This program requires the file WGT5_WC.LIB to be linked.
  12.                                                                               
  13.  *** DATA FILES ***                                                          
  14.  NONE                                                                        
  15.                                                            WATCOM C++ VERSION 
  16. ==============================================================================
  17. */
  18.  
  19. #include <wgt5.h>
  20.  
  21. #define TIMERSPEED 60     /* timer_routine is called 60 times per second */
  22. int timer;                /* Counts how many times it has been called */ 
  23. int clearcount;           /* Counts the number of screen clears. */
  24. void timer_routine (void)
  25. {
  26.  timer++;
  27. }
  28.  
  29.  
  30. void main(void)
  31. {
  32.   short x;
  33.   short y;
  34.   short oldmode;
  35.  
  36.   printf ("WGT Example #3\n\n");
  37.   printf ("This program will use the wcls routine to clear the screen\n");
  38.   printf ("using random colors as fast as it can until you press a key.\n");
  39.   printf ("It will then report the highest frame rate possible on your computer.\n");
  40.   printf ("\n\nPress any key to continue.\n");
  41.   getch ();
  42.  
  43.   if ( !vgadetected() )
  44.   {
  45.     printf("Error - VGA card required for any WGT program.\n");
  46.     exit(0);
  47.   }
  48.  
  49.   oldmode = wgetmode();         /* Store current video mode     */
  50.   vga256();                     /* Initialize WGT system        */
  51.  
  52.   clearcount = 0;
  53.   timer = 0;
  54.  
  55.   winittimer ();
  56.   wstarttimer (timer_routine, TICKS(TIMERSPEED));
  57.  
  58.   while (!kbhit())
  59.   {
  60.                           /* Try including wretrace to see the difference */
  61.   //  wretrace ();        /* Wait for VBLANK to prevent "shearing" */
  62.     wcls(rand() % 256); /* Clear with random color out of 256 */
  63.     clearcount++;
  64.   }
  65.  
  66.   wstoptimer ();
  67.   wdonetimer ();
  68.  
  69.   getch();
  70.   wsetmode(oldmode);            /* Restore old video mode       */
  71.   printf ("%f frames per second\n", (float)clearcount / ((float)timer 
  72.                / (float)TIMERSPEED));
  73.   printf ("This is the highest frame rate your computer can produce for full screen\n");
  74.   printf ("animation.\n");
  75. }
  76.